#include "stdafx.h"
#include "japp.h"
#include <wx/msgdlg.h>
#include <wx/msw/ole/oleutils.h>
#include "jmainframe.h"
#include "japptraits.h"
#include <wx/filename.h>
#include <wx/log.h>
#include "jappconfig.h"
#include "jlogindialog.h"
#include "jglobals.h"
#include "app_res.h"
#include <wx/filesys.h>
#include <wx/fs_arc.h>
#include <wx/fs_mem.h>



IMPLEMENT_APP_CONSOLE(JApp)

JApp::JApp():m_mainFrame(NULL)
{

}

JApp::~JApp()
{

}



bool JApp::OnInit()
{
    wxApp::OnInit();
    wxOleInitialize();

    wxInitAllImageHandlers();

    wxFileSystem::AddHandler(new wxArchiveFSHandler);
    wxFileSystem::AddHandler(new wxMemoryFSHandler);


    wxXmlResource::Get()->InitAllHandlers();  //初始化XML资源文件处理句柄
    InitXmlResource();
    //加载名称为mainicon的icon图标文件作为窗口的图标
    //SetIcon(wxXmlResource::Get()->LoadIcon(wxT("mainicon")));

    //wxBitmap bmDiskMan(wxXmlResource::Get()->LoadBitmap(wxT("appimage")));

    JAppConfig::InitData();

    if(! this->do_login())
    {
        return false;
    }

    m_mainFrame=new JMainFrame();
    m_mainFrame->SetIcon(wxXmlResource::Get()->LoadIcon(wxT("logo")));
    m_mainFrame->Show(true);
    this->SetExitOnFrameDelete(true);
    return true;
}

int JApp::OnExit()
{

    wxOleUninitialize();
    wxApp::OnExit();
    return 0;
}

wxAppTraits *JApp::CreateTraits()
{
    return new JAppTraits();
}

bool JApp::do_login()
{
    JLoginDialog dlg(NULL);
    dlg.SetIcon(wxXmlResource::Get()->LoadIcon(wxT("logo")));
    if(wxID_OK==dlg.ShowModal())
    {
        return true;
    }
    return false;

}
